home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Presentations / Presentations ’97 / Sessions ’97 / Java for Macintosh Applications / JDK Native / TimeUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-27  |  1.2 KB  |  72 lines  |  [TEXT/CWIE]

  1. /*
  2.     TimeUtils.c
  3.  
  4.     Demonstration of JDK Native methods.
  5.  
  6.     © 1997 by Michael J. Webb (mjw@codewell.com)
  7.  
  8. */
  9.  
  10. /* JavaH generated include. */
  11.  
  12. #include "TimeUtils.h"
  13.  
  14. /* MacOS Includes */
  15.  
  16. #include <lowmem.h>
  17. #include <OSUtils.h>
  18.  
  19. /* JDK Includes. */
  20.  
  21. #include <javastring.h>
  22.  
  23. /* ANSI Includes. */
  24.  
  25. #include <stdio.h>
  26. #include <string.h>
  27.  
  28. /** Native method to get the current time.
  29.  */
  30. long TimeUtils_GetRealTime(struct HTimeUtils* this)
  31. {
  32.     long realTime = 0;
  33.     GetDateTime(((unsigned long*)(&realTime)));
  34.     return realTime;
  35. }
  36.  
  37. /** Native method to get the tick count.
  38.  */
  39. long TimeUtils_GetRelativeTime(struct HTimeUtils* this)
  40. {
  41.     SInt32 relTime = 0;
  42.     relTime = LMGetTicks();
  43.     return relTime;
  44. }
  45.  
  46. /** Native method to convert a time to a string.
  47.  */
  48. struct Hjava_lang_String* TimeUtils_GetTimeString(struct HTimeUtils* this, long someTime)
  49. {
  50.     struct Hjava_lang_String*    newString = NULL;
  51.     DateTimeRec                    dateTime;
  52.     char                        buffer[256];
  53.  
  54.     SecondsToDate(someTime, &dateTime);
  55.  
  56.     sprintf
  57.     (
  58.         buffer,
  59.         "%d/%d/%d %d:%d:%d",
  60.         dateTime.day,
  61.         dateTime.month,
  62.         dateTime.year,
  63.         dateTime.hour,
  64.         dateTime.minute,
  65.         dateTime.second
  66.     );
  67.  
  68.     newString = makeJavaString(buffer, strlen(buffer));
  69.  
  70.     return newString;
  71. }
  72.